package com.twu.biblioteca;
import java.io.*;
import  org.junit.Test;
class books
{
    String book_name;
    Boolean booked=false;
    books()
    {}
    books(String book_name)
    {
        this.book_name=book_name;
    }
    void display_book_list(int book_index)
    {
        System.out.println(book_index+".  "+book_name);
    }
    void reserve_book()
    {
        if(this.booked==false)
        {
            System.out.println("enjoy");
            this.booked=true;
        }
        else
            System.out.println("hvnt book yet");
    }
}
class movies
{
    String name, Director,rating;
    int year;
    movies()
    {
    }
    movies(String name,String Director, int year,String rating)
    {
        this.name=name;
        this.Director=Director;
        this.year=year;
        this.rating=rating;
    }
    void show_movie_detail()
    {
        System.out.println(this.name+"\t\t"+this.Director+"\t\t\t"+this.year+"\t\t\t"+this.rating);
    }

}
class users
{
    String name,email,username,password;
    static int Library_number=1111;
    long phone;
    users()
    {
    }
    users(String n,String email,String pass,long ph)
    {
        name=n;
        this.email=email;
        this.username="111"+"-"+Library_number;
        password=pass;
        phone =ph;
        Library_number+=1;
    }
    void display_details()
    {
        System.out.println("personal Details are:\nName:"+name+"\n"+"Email:"+email+"\n"+"Phone number"+phone);
    }
}
public class BibliotecaApp {

    public static void movie_list()
    {
        System.out.println("movie list\n");
        movies movie[]=new movies[15];
        movie[0]=new movies("Gajani","\tAmole Gupte",2007,"5") ;
        movie[1]=new movies("Jab We Met","Imtiaz Ali",2003,"4");
        movie[2]=new movies("Talaash","\tKiran kher",2012,"4");
        movie[3]=new movies("Matrix","\tAndy wacho.",1999,"9");
        movie[4]=new movies("21","\t\tRobert Lukretic",2008,"8");
        movie[5]=new movies("Special 26","Neeraj Pandey",2013,"6");
        movie[6]=new movies("wrong turn","Rob Schmidt",2003,"6");
        movie[7]=new movies("resident","Paul Anderson",2001,"9");
        movie[8]=new movies("Final Des.","James Wong",2000,"9");
        movie[9]=new movies("vivah","\tSuraj bharjatya",2006,"8");
        movie[10]=new movies("Inception","Cristohpher Nolan",2010,"9");
        movie[11]=new movies("Paa","\t\tR.Balki\t",2009,"\t7");
        movie[12]=new movies("3 Idiot","\tRajkumar Hirani",2009,"10");
        movie[13]=new movies("BMB","\t\tRakeysh Omprakash Mehra",2013,"N/A");
        movie[14]=new movies("16 wishes","Peter John DeLuise",2010 ,"7");
        System.out.println("Name\t\t\tDirector\t\t\tyear\t\tRating");
        for(int i=0;i<15;i++)
        {
            movie[i].show_movie_detail();
        }
    }
    public  static void book_list(int flag) throws IOException
    {
        String str="",str1="";
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        books  book[]=new  books[5];
        book[0]=new books("Computer Graphics");
        book[1]=new books("Java Application");
        book[2] =new books(" Let Us C");
        book[3]=new books("System design");
        book[4]=new books("Qualitative Aptitude");
        do {
            System.out.println("\nBook List..");
            for(int i=0;i<5;i++)
            {
                book[i].display_book_list(i+1);
            }
            if(flag==1)
            {
                System.out.println("enter your choice of book to reserve");
                int k=Integer.parseInt(br.readLine());
                book[k].reserve_book();
                System.out.println("Do you want to reserve a book again.. Y/N");
                str1= br.readLine();

            }

        }while (str1.equalsIgnoreCase("Y"));
    }
    public static void main(String[] args) throws IOException
    {
        int ch;
        do {
            System.out.println("\n1. Movie list\n 2. Book list \n3. login\n Enter your choice");
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            ch=Integer.parseInt(br.readLine());
            int flag=0;
            switch(ch)
            {
                case 1:movie_list();
                    break;
                case 2:book_list(flag);
                    break;
                case 3:login();

            }
        }while(ch>=1 && ch<=3);
    }
    public  static  void  login()    throws IOException
    {            int flag=0;
        users user[]=new users[2];
        user[0]=new users("stefan","Stefan@gmail.com","stefan",9413455);
        user[1]=new users("daemon","Daemon@gmail.com","daemon",94136795);
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in)) ;
        System.out.println("Enter username");
        String username=br.readLine();
        System.out.println("Enter password");
        String password=br.readLine();
        if(username.equals(user[0].username)&& password.equals(user[0].password)||(username.equals(user[1].username)&& password.equals(user[1].password)))
        {
            System.out.println("\nYou are logged in............You can reserve books now....\n");
            flag=1;
            int ch;
            do{
                System.out.println("\n1. Movie list\t 2. Book list \t3. personal detaills\t 4.exit\n Enter your choice");
                ch=Integer.parseInt(br.readLine());
                switch (ch)
                {
                    case 1:movie_list();
                        break;
                    case 2:book_list(flag);
                        break;
                    case 3: if(username.equals(user[0].username))
                    {
                        user[0].display_details();
                    }
                    else
                        user[1].display_details();
                }
            }while (ch>=1 && ch<=3);
        }
        else
            System.out.println("Please talk to a Librarian. Thank you.");

    }


}